package com.five.zhh.fiveinfive.common;

import lombok.Data;

@Data
public class ZhhResponse<T> {

    private int code;

    private String message;

    private T data;

    public ZhhResponse() {
    }

    public ZhhResponse(ZhhResponseCode r) {
        this(r.getCode(), r.getMessage());
    }

    public ZhhResponse(ZhhResponseCode r, T data) {
        this(r.getCode(), r.getMessage(), data);
    }

    public ZhhResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ZhhResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <Z> ZhhResponse<Z> success() {
        return new ZhhResponse<>(ZhhResponseCode.SUCCESS);
    }

    public static <Z> ZhhResponse<Z> success(Z data) {
        return new ZhhResponse<Z>(ZhhResponseCode.SUCCESS, data);
    }

    public static <Z> ZhhResponse<Z> failure() {
        return new ZhhResponse<>(ZhhResponseCode.FAIL);
    }

    public static <Z> ZhhResponse<Z> failure(String message) {
        return new ZhhResponse<>(ZhhResponseCode.FAIL.getCode(), message);
    }

    public static <Z> ZhhResponse<Z> failure(ZhhResponseCode r, Z data) {
        return new ZhhResponse<Z>(r, data);
    }
}
